package com.itheima.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.yulichang.base.MPJBaseMapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.itheima.mapper.ChannelsMapper;
import com.itheima.po.MediaChannel;
import com.itheima.service.ChannelService;
import com.itheima.vo.MediaChannelVo;
import lombok.Data;
import org.apache.ibatis.javassist.expr.NewArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @author :wujunjie
 * createTime :2023-01-02 22:29
 * description :
 */
@Service
public class ChannelServiceImpl implements ChannelService {

    @Autowired
    private ChannelsMapper channelsMapper;
    @Override
    public List<MediaChannelVo> selectAllChannels() {
        MPJLambdaWrapper<MediaChannel> selectWrapper = new MPJLambdaWrapper<>();
        selectWrapper.orderByAsc(MediaChannel::getOrd);
        List<MediaChannel> mediaChannels = channelsMapper.selectList(selectWrapper);
        if (CollectionUtils.isEmpty(mediaChannels)){
            return null;
        }
        return BeanUtil.copyToList(mediaChannels, MediaChannelVo.class);
    }
}
